//
//  NSString+formatVerify.m
//  physicalProject
//
//  Created by Westbrook on 2018/5/22.
//  Copyright © 2018年 cjkt. All rights reserved.
//

#import "NSString+formatVerify.h"

@implementation NSString (formatVerify)

+ (BOOL)checkPhoneTypeWithString:(NSString *)string checkingType:(CJKTCheckingType)type {
    
    if (type&captchaChecking) {
        return string.length ==6? YES:NO;
    }
    
    string = [string stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
    
    NSRange stringRange =NSMakeRange(0, string.length);
    
    if (type&phoneChecking) {
        NSRegularExpression *phoneRE = [NSRegularExpression regularExpressionWithPattern:@"^1[\\d]{10}$" options:NSRegularExpressionCaseInsensitive error:nil];
        NSArray *phoneArray = [phoneRE matchesInString:string options:NSMatchingReportProgress range:stringRange];
        if (phoneArray.count) {
            return YES;
        }
    }
    
    if (type&passwordChecking) { //^[a-zA-Z]\w{5,17}$
        
        NSRegularExpression *passwordRE = [NSRegularExpression regularExpressionWithPattern:@"^[a-zA-Z0-9]{6,18}$" options:NSRegularExpressionCaseInsensitive error:nil];
        NSArray *passwordArr = [passwordRE matchesInString:string options:NSMatchingReportProgress range:stringRange];
        
        if(passwordArr.count) {
            
            return YES;
            
        }
        
        
    }
    
    if (type&EmailChecking) {
        NSRegularExpression *mailRE = [NSRegularExpression regularExpressionWithPattern:@"^([a-zA-Z0-9]+[_|\\_|\\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\\_|\\.]?)*[a-zA-Z0-9]+\\.[a-zA-Z]{2,3}$" options:NSRegularExpressionCaseInsensitive error:nil];
        NSArray *mailArray = [mailRE matchesInString:string options:NSMatchingReportProgress range:stringRange];
        if (mailArray.count) {
            return YES;
        }
        
    }
    
    if(type&qqChecking) {
        
        NSRegularExpression *qqRE = [NSRegularExpression regularExpressionWithPattern:@"^[1-9]\\d{4,14}$" options:NSRegularExpressionCaseInsensitive error:nil];
        
        NSArray *qqArray = [qqRE matchesInString:string options:NSMatchingReportProgress range:stringRange];
        if (qqArray.count) {
            return YES;
        }
        
    }
    
    if(type&nicknameChecking) {
        
        NSRegularExpression *nicknameRE = [NSRegularExpression regularExpressionWithPattern:@"^[\u4e00-\u9fa5a-zA-Z0-9_]{4,12}$" options:NSRegularExpressionCaseInsensitive error:nil];
        
        NSArray *nickArray = [nicknameRE matchesInString:string options:NSMatchingReportProgress range:stringRange];
        if (nickArray.count) {
            return YES;
        }
        
    }
    
    if(type&usernameCHecking) {
        
        NSRegularExpression *usernameRE = [NSRegularExpression regularExpressionWithPattern:@"^[\u4e00-\u9fa5]{2,5}$" options:NSRegularExpressionCaseInsensitive error:nil];
        
        NSArray *usernameArray = [usernameRE matchesInString:string options:NSMatchingReportProgress range:stringRange];
        if (usernameArray.count) {
            return YES;
        }
        
    }
    
    
    return NO;
}

@end
